package com.jwgf.smarowindingmachine_unity.ui;

import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;

import androidx.fragment.app.DialogFragment;

import com.jwgf.group.GroupMap;
import com.jwgf.smarowindingmachine_unity.R;
import com.jwgf.smarowindingmachine_unity.logic.Report;
import com.jwgf.smarowindingmachine_unity.logic.UnitUtils;

import java.util.List;

public class TubeLengthSampleDialog extends DialogFragment {
    public static final String GROUP = "group";
    private static final String SPINDLE = "spindle";
    private static final String ORIGIN = "origin";
    private static final String BASE = "base";

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        Bundle bd = getArguments();
        int group = bd.getInt(GROUP);
        List<Integer> spindleList = GroupMap.getInstance().getSpindleList(group);
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        String[] items = new String[spindleList.size()];
        for (Integer spindle : spindleList) {
            String uiLength = UnitUtils.getUILength(String.valueOf(UnitUtils.pulse2Length(Report.getInstance().getTubeLength(spindle), spindle)));
            items[spindle - spindleList.get(0)] = "" + spindle + " : " + uiLength;
        }
        builder.setTitle(R.string.tube_length_sample_value);
        builder.setItems(items, null);
        return builder.create();
    }

}
